package com.javatest;

/**
 * @author LL
 * 编写一段代码，打印出一个 M 行 N 列的二维数组的转置（交换行和列）。
 * @create 2021-01-13 10:07
 */
public class Subject25 {

    public static void test(){
        int[][] a = {   {1,2,3,4},
                        {1,2,3,4},
                        {1,2,3,4}
                    };
        int M = a.length;
        int N = a[0].length;
        int[][] b = new int[N][M];
        for (int i = 0; i < N; i++) {//4
            for (int j = 0; j < M; j++) {//3
                b[i][j] = a[j][i];
            }
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                System.out.print(b[i][j]);
            }
            System.out.println();
        }

    }
    public static void main(String[] args) {
        test();
    }
}
